package fun.yao.common.monitor.info;

import fun.yao.common.Constant;
import fun.yao.common.msg.HashtableMsg;
import fun.yao.common.uitls.LogUtil;

import java.util.Hashtable;

/**
 * 线程信息
 * @author longjinglai
 *
 */
public class ThreadInfo implements IMonitorInfo {

    /**总线程数*/
    private int total = 0;

    /**活跃线程数*/
    private int alive = 0;

    public int getTotal() {
        return total;
    }

    public int getAlive() {
        return alive;
    }



    public void setTotal(int total) {
        this.total = total;
    }

    public void setAlive(int alive) {
        this.alive = alive;
    }

    public ThreadInfo()
    {

    }

    public ThreadInfo(HashtableMsg htm)
    {
        Hashtable<String, String> mapThread = htm.get(0);
        if(mapThread!=null)
        {
            this.alive = Integer.parseInt(mapThread.get("alive"));
            this.total = Integer.parseInt(mapThread.get("total"));
        }
    }


    public HashtableMsg toHashtableMsg()
    {
        HashtableMsg htm = new HashtableMsg();
        Hashtable<String, String> mapThread = new Hashtable<String, String>();
        mapThread.put("total", this.getTotal()+"");
        mapThread.put("alive", this.getAlive()+"");
        htm.add(mapThread);
        return htm;
    }

    @Override
    public String toString() {
        return "ThreadInfo [alive=" + alive + ", total=" + total + "]";
    }

    public static void main(String[] args)
    {
        ThreadInfo threadInfo = new ThreadInfo();
        System.out.println("总线程:" + threadInfo.getTotal() );
        System.out.println("活跃线程:" + threadInfo.getAlive() );
    }

    public void print(StringBuilder sbOut) {
        try
        {
            sbOut.append("总线程："+this.getTotal()+"，活跃线程："+this.getAlive()+"\n");
        }catch (Exception e) {
            LogUtil.WriteLog(Constant.BADLY_ERROR, e);
        }
    }


}

